home *** CD-ROM | disk | FTP | other *** search
- Path: news.tek.com!mdhost!gaulandm
- From: gaulandm@mdhost.cse.tek.com (Michael Alan Gauland)
- Newsgroups: comp.lang.c++
- Subject: Can I overload "*" without class overhead?
- Date: 28 Feb 1996 17:13:55 GMT
- Organization: Tektronix, Inc, Beaverton, OR, USA
- Sender: gaulandm@mdhost (Michael Alan Gauland)
- Distribution: world
- Message-ID: <4h22gj$pqa@tekadm1.cse.tek.com>
- NNTP-Posting-Host: hardtime.cse.tek.com
-
- I need to implement some fixed-point math routines. I've got a set of
- 16-bit data, with an implied decimal point in the middle of the number.
- To multiply two such values requires a right shift so the decimal point
- of the result is in the right place:
-
- result = ((int32)a * b) >> 8;
-
- This looks sloppy, and every place in the code I put such an operation
- increases the chances of getting it wrong. It seems a natural place
- to take advantage of C++'s operator overloading. My attempts to date,
- however, have been slow (though elegant). I expect this is due to the
- added overhead of a struct vs. an int. Is there any way to work around
- this? Of course, I could use a fuction like "FixedPointMultiply(a,b)",
- but I'll lose the added security of rigid typing.
-
- Can anyone offer any helpful advice, or is this just something elegant C++ can't
- do as efficiently as sloppy C?
-
- Thanks,
- Mike
-
- ---------------------------------------------------
- Michael A. Gauland gaulandm@mdhost.cse.tek.com
- AA7JF (503) 627-5067
-
-